<?php
    $url = new Url();
    $current_url = Common::getCurrentUrl();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);    
?>
<script type="text/javascript">
    function ajaxSaveTheme(){
        var strUrl = "<?=$url->createUrl("theme/ajaxSaveTheme") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                theme_name:$("#theme_name").val(),
                theme_path:$("#theme_path").val(),
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
    function ajaxQuickUpdate(id){
        var strUrl = "<?=$url->createUrl("theme/ajaxQuickUpdate") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                theme_name:$("#theme_name_"+id).val(),
                theme_path:$("#theme_path_"+id).val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    } 
    function ajaxDelete(id){
        var strUrl = "<?=$url->createUrl("theme/ajaxDelete") ?>";
        if(confirm('Bạn có chắc chắn muốn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>         
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <form name="SearchForm" method="GET">
            <ul class="form4">
                <li class="clearfix"><label><strong>Tên theme </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:196px;" value="<?php echo $theme_name;?>" name="theme_name">
                    </div>
                </li>
                <li class="clearfix"><label><strong>Path theme </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:196px;" value="<?php echo $theme_path;?>" name="theme_path">
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" value=" Tìm kiếm" class="btn-bigblue"> 
                    </div>
                </li>

            </ul>
        </form>
    </div>
    <div class="box">
        <div class="fillter clearfix">
            <div class="fl"></div>
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="6%"><strong>Mã</strong></td>
                        <td width="24%"><strong>Ảnh đại diện</strong></td>
                        <td width="14%"><strong>Tên theme</strong></td>
                        <td width="5%"><strong>Path theme</strong></td>
                        <td width="8%"><strong>Người tạo</strong></td>
                        <td width="8%"><strong>Ngày tạo</strong></td>
                        <td width="16%"><strong>Hành động</strong><br></td>
                    </tr>
                    <tr>
                            <td class="middle">&nbsp;</td>
                            <td>&nbsp;</td>
                            <td><input type="text" id="theme_name" value=""/></td>
                            <td><input type="text" id="theme_path" value=""/></td>
                            <td>&nbsp;</td> 
                            <td>&nbsp;</td> 
                            <td>
                            <input type="button" onclick="ajaxSaveTheme();" id="button_save" value="Thêm Mới" class="btn-bigblue">                           
                            </td>
                        </tr>
                    <?php foreach($data as $key=>$value){
                          $screen_short = Yii::app()->params["url_theme_shop"].$value["theme_path"].'/images/Theme-style.jpg';
                        ?>   
                        <tr>
                            <td class="middle"><?php echo $value["id"]?></td>
                            <td><img src="<?php echo $screen_short?>" style="width: 100px; height: 92px;"/></td>
                            <td class="middle"><input type="text" id="theme_name_<?php echo $value["id"]?>" value="<?php echo $value["theme_name"]?>"/></td>
                            <td class="middle"><input type="text" id="theme_path_<?php echo $value["id"]?>" value="<?php echo $value["theme_path"]?>"/></td>
                            <td class="middle"><?php echo $value["user_create"]?></td> 
                            <td class="middle"><?php echo date("d-m-Y H:i:s",$value["date_create"])?></td> 
                            <td class="middle">
                                <a class="s14" href="javascript:void(0)" onclick="ajaxQuickUpdate('<?php echo $value["id"]?>')"> Lưu </a> |                                 
                                <a href="javascript:void(0)" onclick="ajaxDelete('<?php echo $value["id"]?>');">  Xóa  </a> |
                            </td>
                        </tr>
                        <?php }?>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>

    </div>
        </div>